<template>
	<view>
		<add1 :addForm="add1Form" @updateaddOne="updateaddOne" :editId="editId" v-if="nowSetp===0"></add1>
		<add2 @onBack="nowSetp=0" :editId="editId" :tempId="tempId" :addForm="add1Form" @updateaddTwo="updateaddTwo"
			v-else-if="nowSetp==1"></add2>
		<add3 :editId="editId" :typeForm="typeForm" :addForm="add1Form" @updateaddThree="updateaddThree"
			@onBack="nowSetp=1,add1Form=tempForm" :tempId="tempId" :tempImg="tempImg" v-else-if="nowSetp==2"></add3>
		<add4 :editId="editId" :addForm="add1Form" @onBack="nowSetp=2,typeForm='prev'" v-else-if="nowSetp==3"></add4>
	</view>
</template>

<script>
	import add1 from './components/add_1.vue'
	import add2 from './components/add_2.vue'
	import add3 from './components/add_3.vue'
	import add4 from './components/add_4.vue'
	export default {
		components: {
			add1,
			add2,
			add3,
			add4
		},
		data() {
			return {
				nowSetp: '',
				tempForm: {},
				add1Form: {},
				add3Form: {},
				tempId: '',
				tempImg: '',
				editId: '',
				typeForm: ''
			}
		},
		onLoad({
			id
		}) {
			this.editId = id
			id && this.getDetail(id);
			if (!id) {
				this.nowSetp = 0
			}
			// if (Object.keys(this.vuex_tempForm).length && !id) {
			// 	this.add1Form = this.vuex_tempForm
			// 	this.nowSetp = 0
			// }
		},
		// onUnload() {
		// 	if (this.editId) {
		// 		this.$store.commit('$uStore', {
		// 			name: 'vuex_tempForm',
		// 			value: {}
		// 		})
		// 	}
		// },
		methods: {
			getDetail(id) {
				this.$API.getActivityNew({
					id
				}).then(res => {
					console.log(res.data);
					this.add1Form = res.data
					this.$nextTick(() => {
						this.nowSetp = 0
					})
				})
			},
			updateaddOne(e) {
				// console.log(e);
				// this.$store.commit('$uStore', {
				// 	name: 'vuex_tempForm',
				// 	value: e
				// })
				this.add1Form = e
				this.tempForm = e
				this.nowSetp = 1
			},
			updateaddTwo(e) {
				this.tempId = e.tempId
				if (e.tempId === '') {
					if (this.editId) {
						this.add1Form.share_image = this.add1Form.share_image
					} else {
						this.add1Form.share_image = this.add1Form.images
					}
				}
				this.tempForm.templateid = e.tempId
				if (e.tempId == 0) {
					this.tempForm.template_custom_image = e.template_custom_image
				}
				this.add1Form.template_custom_image = e.template_custom_image
				this.tempImg = this.add1Form.images
				this.nowSetp = 2
				this.typeForm = 'next'
			},
			updateaddThree(e) {
				console.log(e);
				this.add1Form = {
					...this.add1Form,
					...e
				}
				// this.$store.commit('$uStore', {
				// 	name: 'vuex_tempForm',
				// 	value: {
				// 		...this.add1Form,
				// 		...e
				// 	}
				// })
				this.nowSetp = 3
			},
		}
	}
</script>

<style lang="scss" scoped>
</style>